package com.ssy.lingxi.after.sale.controller.mobile;

import com.ssy.lingxi.after.sale.api.model.vo.request.CommonIdVO;
import com.ssy.lingxi.after.sale.model.constant.RepairGoodsReasonEnum;
import com.ssy.lingxi.after.sale.model.vo.request.*;
import com.ssy.lingxi.after.sale.model.vo.response.*;
import com.ssy.lingxi.after.sale.service.IRepairGoodsDetailService;
import com.ssy.lingxi.after.sale.service.IRepairGoodsService;
import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.ResponseCode;
import com.ssy.lingxi.common.response.Wrapper;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu App - 售后维修相关接口
 * @author 伍将
 * @date 2020/12/30
 * @version 2.0.0
 */
@RestController
@RequestMapping("/as/mobile/repairGoods")
public class MobileRepairGoodsController extends BaseController {

    @Resource
    private IRepairGoodsService repairApplyService;

    @Resource
    private IRepairGoodsDetailService repairGoodsService;

    /**
     * 分页查询采购商售后维修
     * @author 伍将
     * @date 2020/12/30
     **/
/*    @RequestMapping(value = "/pageByConsumer", method = RequestMethod.GET)
    public Wrapper<PageData<RepairGoodsQueryVO>> pageByConsumer(HttpServletRequest httpRequest, @Valid RepairGoodsPageByConsumerVO pageVO) {
        return repairApplyService.pageByConsumer(getSysUser(httpRequest), pageVO);
    }*/

    /**
     * 退货原因-列表
     * @return
     */
    @RequestMapping(value = "/getReasonList", method = RequestMethod.GET)
    public Wrapper<List<DropdownItemVO>> getReasonList() {
        return Wrapper.success(RepairGoodsReasonEnum.toDropdownItems());
    }

    /**
     * 分页查询采购商售后维修-新
     * @author ds
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/pageByConsumer", method = RequestMethod.GET)
    public Wrapper<PageData<RepairGoodsQueryAppVO>> pageByConsumer(HttpServletRequest httpRequest, @Valid RepairGoodsPageAppByConsumerVO pageVO) {
        return repairApplyService.pageAppByConsumer(getSysUser(httpRequest), pageVO);
    }

    /**
     * 查询采购商售后维修详情
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/getDetailByConsumer", method = RequestMethod.GET)
    public Wrapper<RepairGoodsDetailVO> getDetailByConsumer(HttpServletRequest httpRequest, Long repairId) {
        return repairApplyService.getDetailByConsumer(getSysUser(httpRequest), repairId);
    }

    /**
     * 分页查询采购商维修商品
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/pageRepairGoods", method = RequestMethod.GET)
    public Wrapper<PageData<RepairGoodsDetailQueryVO>> pageList(@Valid RepairGoodsDetailPageVO pageVO) {
        return repairGoodsService.pageList(pageVO);
    }

    /**
     * 分页查询采购商待提交售后维修
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/pageToBeSubmitByConsumer", method = RequestMethod.GET)
    public Wrapper<PageData<RepairGoodsQueryVO>> pageToBeSubmitByConsumer(HttpServletRequest httpRequest, @Valid RepairGoodsPageByConsumerVO pageVO) {
        return repairApplyService.pageToBeSubmitByConsumer(getSysUser(httpRequest), pageVO);
    }

    /**
     * 采购商保存售后维修
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/saveByConsumer", method = RequestMethod.POST)
    public Wrapper<Long> saveByConsumer(HttpServletRequest httpRequest, @RequestBody @Valid RepairGoodsSaveVO saveVO) {
        Wrapper<Long> save = repairApplyService.save(getSysUser(httpRequest), saveVO);
        if(save.getCode()== ResponseCode.SUCCESS.getCode()) {
            Wrapper<Void> submit = repairApplyService.submit(getSysUser(httpRequest), save.getData());
            if(submit.getCode()!= ResponseCode.SUCCESS.getCode()){
                return Wrapper.fail(submit.getCode(),submit.getMessage());
            }
        }
        return save;
    }

    /**
     * 采购商删除售后维修
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/deleteByConsumer", method = RequestMethod.POST)
    public Wrapper<Void> deleteByConsumer(HttpServletRequest httpRequest, @RequestBody CommonIdVO commonIdVO) {
        return repairApplyService.delete(getSysUser(httpRequest), commonIdVO.getDataId());
    }

    /**
     * 采购商提交售后维修
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/submitByConsumer", method = RequestMethod.POST)
    public Wrapper<Void> submitByConsumer(HttpServletRequest httpRequest, @RequestBody CommonIdVO commonIdVO) {
        return repairApplyService.submit(getSysUser(httpRequest), commonIdVO.getDataId());
    }

    /**
     * 分页查询采购商待确认完成售后维修
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/pageToBeConfirmComplete", method = RequestMethod.GET)
    public Wrapper<PageData<RepairGoodsQueryVO>> pageToBeConfirmComplete(HttpServletRequest httpRequest, @Valid RepairGoodsPageByConsumerVO pageVO) {
        return repairApplyService.pageToBeConfirmComplete(getSysUser(httpRequest), pageVO);
    }

    /**
     * 采购商确认售后完成
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping("/confirmComplete")
    public Wrapper<Void> confirmComplete(HttpServletRequest httpRequest, @RequestBody @Valid RepairGoodsConfirmCompleteVO completeVO) {
        return repairApplyService.confirmComplete(getSysUser(httpRequest), completeVO);
    }

    /**
     * 分页查询列表页面搜索条件内容
     * @author 伍将
     * @date 2020/10/17
     **/
    @RequestMapping(value = "/pageItems", method = RequestMethod.GET)
    public Wrapper<RepairGoodsPageItemsVO> pageItems(HttpServletRequest httpRequest) {
        return repairApplyService.pageItems(getSysUser(httpRequest));
    }
}
